﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace HBFramework
{
    public class RandomUtility
    {
        /// <summary>
        /// 获取范围内随机位置
        /// </summary>
        /// <param name="center"></param>
        /// <param name="radius"></param>
        /// <param name="axis"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static List<Vector3> GetRandomPosition(Vector3 center, float radius, int axis, int count)
        {
            List<Vector3> result = new List<Vector3>();
            for (int i = 0; i < count; i++)
            {
                var random = Random.insideUnitCircle * radius;
                Vector3 p = new Vector3();
                switch (axis)
                {
                    case 0:
                        //x轴
                        p = new()
                        {
                            x = center.x,
                            y = center.y + random.x,
                            z = center.z + random.y
                        };
                        break;
                    case 1:
                        //y轴
                        p = new()
                        {
                            x = center.x + random.x,
                            y = center.y,
                            z = center.z + random.y
                        };
                        break;
                    case 2:
                        //z轴
                        p = new()
                        {
                            x = center.x + random.x,
                            y = center.y + random.y,
                            z = center.z
                        };
                        break;
                }
                result.Add(p);
            }
            return result;
        }
    }
}